from wtforms import StringField, IntegerField
from wtforms.validators import DataRequired, length
from app.validators.base import BaseForm as Form
from app.libs.enums import ClientTypeEnum


class ClientForm(Form):
    # 账号
    account = StringField(validators=[
        DataRequired(message='账号不能为空'), length(min=5, max=32)
    ])
    # 密码
    secret = StringField(validators=[
        DataRequired()
    ])
    # 类型
    type = IntegerField(validators=[
        DataRequired()
    ])

    def validate_type(self, value):
        try:
            self.type.data = ClientTypeEnum(value.data)
        except ValueError as e:
            raise e


class TokenForm(Form):
    token = StringField(validators=[DataRequired()])
